package com.tour.controller;

import com.tour.bean.Consumer;
import com.tour.bean.ReturnT;
import com.tour.bean.UserScenic;
import com.tour.service.UserHotelService;
import com.tour.service.UserScenicService;
import com.tour.service.UserTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.management.ObjectName;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName UserScenicController
 * @Author 张梦兴
 * @Date 2020/3/15 20:21
 * @describe
 * 个人中心关联页面
 */
@RestController
@RequestMapping("user")
public class PersonCenterController {

    @Autowired
    private UserScenicService userScenicService;
    @Autowired
    private UserHotelService userHotelService;
    @Autowired
    private UserTicketService userTicketService;

    /**
     * 初始化个人中心页面
     * @param request
     * @return
     */
    @RequestMapping("/initPage")
    public Object initLoad(HttpServletRequest request){
        Consumer userInfo = (Consumer) request.getSession().getAttribute("userInfo");
        if(null==userInfo){
            ReturnT<String> returnT = new ReturnT<>(501, "用户未登录");
            return returnT;
        }
        int userId=userInfo.getId();
        //查询到景区
        List<Map<String, Object>> scenic = userScenicService.getUserScenicByUserId(userId);
        List<Map<String, Object>> hotel = userHotelService.getUserHotelByUserId(userId);
        List<Map> ticket = userTicketService.getUserTicketById(userId);
        Map<String,Object> result=new HashMap<>();
        result.put("baseInfo", userInfo);
        result.put("scenic", scenic);
        result.put("hotel", hotel);
        result.put("ticket", ticket);
        ReturnT<Map<String,Object>> value=new ReturnT<>(result);
        return value;
    }



    /**
     * [刪除]
     * @author
     * @date 2020/03/15
     **/
    @RequestMapping("/delete")
    public ReturnT<String> delete(int id){
        return userScenicService.delete(id);
    }



    /**
     * [查询] 根据主键 id 查询
     * @author
     * @date 2020/03/15
     *
     * @return*/
    @RequestMapping("/load")
    public UserScenic load(int id){
        return userScenicService.load(id);
    }





}
